<template>
  <page-header-wrapper :title="false">
    <a-card
      title="快速搜索"
    >
      <a-tabs type="card" @change="onTabs">
        <template slot="tabBarExtraContent">
          <a-input-search style="width: 500px" placeholder="输入要搜索的内容" enter-button @search="onSearch" />
        </template>
        <a-tab-pane key="1" tab="手机号"></a-tab-pane>
        <a-tab-pane key="2" tab="客户姓名"></a-tab-pane>
        <a-tab-pane key="3" tab="合同号"></a-tab-pane>
        <a-tab-pane key="4" tab="商标/专利名称"></a-tab-pane>
        <a-tab-pane key="5" tab="注册名称"></a-tab-pane>
        <a-tab-pane key="6" tab="注册号"></a-tab-pane>
      </a-tabs>
      <a-table
        v-if="visible"
        :row-key="(record) => record.customer_id"
        :columns="searchColumns"
        :data-source="resultData"
      >
        <template slot="action" slot-scope="text,record">
          <a-button type="primary" size="small" @click="toDetail(record.customer_id)">查看</a-button>
        </template>
      </a-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { STable } from '@/components'
// import { onSearch } from '@/api/common'
import col from '@/columns/search'
import { onSearch } from '@/api/common'
const searchColumns = col.result

export default {
  components: {
    STable
  },
  name: 'Search',
  data () {
    return {
      searchColumns,
      resultData: [],
      currentTab: '1',
      visible: false
    }
  },
  methods: {
    onTabs (key) {
      this.currentTab = key
      this.visible = false
    },
    onSearch (value) {
      const app = this
      const parameter = {}
      if (value === '') {
        app.$warning({
          title: '搜索内容不能为空'
        })
        return false
      }
      if (app.currentTab === '1') {
        parameter['filter[phone]'] = value
      }
      if (app.currentTab === '2') {
        parameter['filter[customer_name]'] = value
      }
      if (app.currentTab === '4') {
        parameter['filter[tm_name]'] = value
      }
      if (app.currentTab === '3') {
        parameter['filter[contract_no]'] = value
      }
      if (app.currentTab === '5') {
        parameter['filter[name]'] = value
      }
      if (app.currentTab === '6') {
        parameter['filter[reg_no]'] = value
      }
      onSearch(parameter).then(res => {
        if (res.status === 0) {
          app.resultData = res.result.data
          app.visible = true
          setTimeout(() => {
            app.$refs.table.refresh(true)
          }, 500)
        } else {
          app.$warning({
            title: res.msg
          })
        }
      })
    },
    toDetail (id) {
      this.$router.push({ name: 'CustomerDetail', params: { id: id } })
    }
  }
}
</script>

<style scoped>

</style>
